home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / libogg / libvorbis-1.0rc3 / examples / chaining_example.c next >
Encoding:
C/C++ Source or Header  |  2002-10-27  |  2.6 KB  |  71 lines

  1. /********************************************************************
  2.  *                                                                  *
  3.  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
  4.  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
  5.  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6.  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  7.  *                                                                  *
  8.  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
  9.  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
  10.  *                                                                  *
  11.  ********************************************************************
  12.  
  13.  function: illustrate simple use of chained bitstream and vorbisfile.a
  14.  last mod: $Id: chaining_example.c,v 1.15 2001/12/20 01:00:24 segher Exp $
  15.  
  16.  ********************************************************************/
  17.  
  18. #include <vorbis/codec.h>
  19. #include <vorbis/vorbisfile.h>
  20.  
  21. #ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */
  22. #include <io.h>
  23. #include <fcntl.h>
  24. #endif
  25.  
  26. int main(){
  27.   OggVorbis_File ov;
  28.   int i;
  29.  
  30. #ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */
  31.   /* Beware the evil ifdef. We avoid these where we can, but this one we 
  32.      cannot. Don't add any more, you'll probably go to hell if you do. */
  33.   _setmode( _fileno( stdin ), _O_BINARY );
  34.   _setmode( _fileno( stdout ), _O_BINARY );
  35. #endif
  36.  
  37.   /* open the file/pipe on stdin */
  38.   if(ov_open(stdin,&ov,NULL,-1)<0){
  39.     printf("Could not open input as an OggVorbis file.\n\n");
  40.     exit(1);
  41.   }
  42.   
  43.   /* print details about each logical bitstream in the input */
  44.   if(ov_seekable(&ov)){
  45.     printf("Input bitstream contained %ld logical bitstream section(s).\n",
  46.        ov_streams(&ov));
  47.     printf("Total bitstream playing time: %ld seconds\n\n",
  48.        (long)ov_time_total(&ov,-1));
  49.  
  50.   }else{
  51.     printf("Standard input was not seekable.\n"
  52.        "First logical bitstream information:\n\n");
  53.   }
  54.  
  55.   for(i=0;i<ov_streams(&ov);i++){
  56.     vorbis_info *vi=ov_info(&ov,i);
  57.     printf("\tlogical bitstream section %d information:\n",i+1);
  58.     printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n",
  59.        vi->rate,vi->channels,ov_bitrate(&ov,i)/1000,
  60.        ov_serialnumber(&ov,i));
  61.     printf("\t\theader length: %ld bytes\n",(long)
  62.        (ov.dataoffsets[i]-ov.offsets[i]));
  63.     printf("\t\tcompressed length: %ld bytes\n",(long)(ov_raw_total(&ov,i)));
  64.     printf("\t\tplay time: %lds\n",(long)ov_time_total(&ov,i));
  65.   }
  66.  
  67.   ov_clear(&ov);
  68.   return 0;
  69. }
  70.  
  71.